import { useGetProductsQuery } from '../api/productsApiSlice'
import { selectCatalogPage, selectSearch } from '../store/reducers/selectors'
import { DEFAULT_ITEMS_PER_PAGE } from '../store/reducers/slices/paginationSlice'
import { useSkipAccessToken } from './useSkipAccessToken'
import { useAppSelector } from '../hooks'

export const useSelectProducts = () => {
	const search = useAppSelector(selectSearch)
	const page = useAppSelector(selectCatalogPage)
	const params = {
		page: page,
		limit: DEFAULT_ITEMS_PER_PAGE,
		search: search,
	}
	const hooks = useGetProductsQuery(params, useSkipAccessToken())
	return hooks
}
